home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK2.toast / Development Kits (Disc 2) / QuickDraw GX / Programming Stuff / Sample Code / Printing Samples / Printer Drivers… / CustomWriterGX / ChooserLDEF.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-04  |  5.1 KB  |  183 lines  |  [TEXT/MPS ]

  1. /*
  2.     FILENAME
  3.         ChooserLDEF.c
  4.  
  5.     DESCRIPTION
  6.         Contains code for LDEF resource used by the Chooser.
  7.  
  8.     COPYRIGHT
  9.         Copyright © 1995 Apple Computer, Inc.
  10.         All rights reserved.
  11.     
  12.     Modification history
  13.         10/04/95 - David Hayward -    Version 1.0.4 modified code so that
  14.                                     the driver can be build under MPW,
  15.                                     Metrowerks, and Symantec.  In general,
  16.                                     all that was required to do this was 
  17.                                     to add an inline-assembly jumptable
  18.                                     and to store all globals off of the
  19.                                     message manager instance context.
  20.                                     Also made a few changes so that the
  21.                                     driver can be rebuilt to support any
  22.                                     resolution by changing the #defines
  23.                                     kResolution and kPatStretch in
  24.                                     "CommonDefines.h"
  25.  
  26.         06/14/95 - Dave Hersey -    Version 1.0.3 to fix a bug in
  27.                                     CustomBufferingAndIO.c when creating
  28.                                     high-res PICTs, and to make the size
  29.                                     of buffers more flexible.
  30.  
  31.         05/26/95 - Dave Hersey -    Version 1.0.2 to add the new 'outp'
  32.                                     desktop printer resource in NewApp.c.
  33.  
  34.         05/03/95 - Dave Hersey -    Version 1.0.1 to fix some minor bugs in
  35.                                     CustomBufferingAndIO.c.
  36.  
  37.         01/14/95 - Dave Hersey -    Created from the shell of a hollowed-out
  38.                                     ImageWriter driver.
  39. */
  40.  
  41. #include <Lists.h>
  42. #include <Types.h>
  43. #include <Resources.h>
  44. #include <QuickDrawText.h>
  45. #include <ToolUtils.h>
  46. #include <LowMem.h>
  47. #include <GXPrinting.h>
  48. #include "ChooserLDEF.h"
  49.  
  50.  
  51. pascal void        main (short message, Boolean select, Rect *theRect,
  52.                      Cell theCell, short dataOffset, short dataLen, ListHandle theList);
  53.  
  54.  
  55. /*    -----------------------------------------------------------------------
  56.     LDEF is our driver's Chooser LDEF.
  57.  
  58.     This is an LDEF that simply plots an icon, and lets the user "Create."
  59.  
  60.     -----------------------------------------------------------------------    */
  61.  
  62. pascal void main (
  63.     short         message,        // What operation to perform on list
  64.     Boolean     select,            // Is this cell to be selected or not?
  65.     Rect        *theRect,        // Rectangle of this cell, clipped to window
  66.     Cell        theCell,        // Which cell this is
  67.     short        dataOffset,        // Offset into data for this cell
  68.     short        dataLen,        // Length of data for this cell
  69.     ListHandle    theList)        // The list to act upon
  70. {
  71. #pragma unused (theCell, dataOffset, dataLen)
  72.  
  73.         Handle        cicnHdl;
  74.         Rect        iconRect;
  75.         char        userPrompt[] = "\pPrint to Disk";
  76.  
  77.         switch (message)
  78.         {
  79.             case lInitMsg:
  80.                 {
  81.                     Cell    aCell = {0, 1};
  82.                     (*theList)->userHandle = (Handle) GetCIcon(r_ChooserIcon);
  83.     
  84.                     if ((*theList)->userHandle)
  85.                     {
  86.                         DetachResource((*theList)->userHandle);
  87.                         LSetCell((Ptr) &userPrompt[1], userPrompt[0], aCell, theList);
  88.                         LSetSelect(true, aCell,theList);
  89.                     }
  90.                 }
  91.                 break;
  92.                 
  93.             case lCloseMsg:
  94.                 if ((*theList)->userHandle)
  95.                 {
  96.                     DisposeCIcon((CIconHandle) (*theList)->userHandle);
  97.                     (*theList)->userHandle = nil;
  98.                 }
  99.                 break;
  100.  
  101.             case lHiliteMsg:
  102.             case lDrawMsg:
  103.                 cicnHdl = (*theList)->userHandle;
  104.                 if (cicnHdl == nil) break;
  105.                 
  106.                 // draw the cell as an icon
  107.                 // center the icon rect on the list with a top margin of 10 pixels
  108.  
  109.                 iconRect.top = theRect->top + 10;
  110.                 iconRect.left = theRect->left + ((theRect->right - theRect->left) >> 1) - 16;
  111.                 iconRect.bottom = iconRect.top + 32;
  112.                 iconRect.right = iconRect.left + 32;
  113.                     
  114.                     
  115.                 // draw the icon
  116.  
  117.                 if (cicnHdl != nil)
  118.                     PlotCIcon(&iconRect, (CIconHandle) cicnHdl);
  119.                                 
  120.                 // Get the general area under the icon in which to draw the label
  121.  
  122.                 iconRect.left = theRect->left + 2;
  123.                 iconRect.right = iconRect.left + (**theList).cellSize.h - 2;
  124.                 iconRect.top = iconRect.bottom + 2;
  125.                 iconRect.bottom = theRect->bottom;
  126.         
  127.                 // use a nice small font for the label            
  128.  
  129.                 TextFont(applFont);
  130.                 TextSize(9);
  131.                     
  132.                 {
  133.                     short            labelWidth;
  134.                     short            rectWidth;
  135.                     short            labelHeight;
  136.                     FontInfo        theInfo;
  137.                     unsigned char    theHilightMode;
  138.                     
  139.     /*    Get rid of any previous label, compute the height of the new label,
  140.         compute where to draw the text, truncate the string to fit within the box,
  141.         compute the new width of the string, center the string, and draw it.
  142.     */
  143.                     EraseRect(&iconRect);
  144.                     iconRect.top += 2;
  145.                         
  146.                     GetFontInfo(&theInfo);
  147.                     labelHeight = theInfo.ascent +theInfo.leading;
  148.                 
  149.                     iconRect.bottom = iconRect.top + labelHeight;
  150.                     rectWidth = iconRect.right-iconRect.left;
  151.                     
  152.     // Not very localizable...  Use resources in the real world.
  153.  
  154.                     TruncString(rectWidth, (unsigned char *) userPrompt, smTruncEnd);
  155.                     labelWidth = StringWidth((unsigned char const *) userPrompt);
  156.                 
  157.                     iconRect.left += (rectWidth >> 1) - (labelWidth >> 1);
  158.                     MoveTo(iconRect.left, iconRect.bottom);
  159.                     DrawString((unsigned char const *) userPrompt);
  160.  
  161.     // If selecting the icon, highlight the text.
  162.  
  163.                     if (select)
  164.                     {
  165.                         iconRect.right = iconRect.left + labelWidth;
  166.                         iconRect.bottom += theInfo.descent;
  167.                         
  168.                         InsetRect(&iconRect, -1, -1);
  169.                         
  170.                         theHilightMode = LMGetHiliteMode();
  171.                         BitClr(&theHilightMode, pHiliteBit);
  172.                         LMSetHiliteMode(theHilightMode);
  173.                         InvertRect(&iconRect);
  174.                     }
  175.  
  176.                     TextFont(applFont);
  177.                     TextSize(0);
  178.                 }
  179.                 break;
  180.         }
  181. }
  182.  
  183.